home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / os2 / adaptor.zip / ADAPT.ZIP / adaptor / src / tempscal.c < prev    next >
Text File  |  1994-01-03  |  13KB  |  638 lines

  1. # include "TempScal.h"
  2. # include "yyTScala.w"
  3. # include <stdio.h>
  4. # if defined __STDC__ | defined __cplusplus
  5. #  include <stdlib.h>
  6. # else
  7.    extern void exit ();
  8. # endif
  9. # include "Tree.h"
  10. # include "Definiti.h"
  11.  
  12. # ifndef NULL
  13. # define NULL 0L
  14. # endif
  15. # ifndef false
  16. # define false 0
  17. # endif
  18. # ifndef true
  19. # define true 1
  20. # endif
  21.  
  22. # ifdef yyInline
  23. # define yyALLOC(tree, free, max, alloc, nodesize, make, ptr, kind) \
  24.   if ((ptr = (tree) free) >= (tree) max) ptr = alloc (); \
  25.   free += nodesize [kind]; \
  26.   ptr->yyHead.yyMark = 0; \
  27.   ptr->Kind = kind;
  28. # else
  29. # define yyALLOC(tree, free, max, alloc, nodesize, make, ptr, kind) ptr = make (kind);
  30. # endif
  31.  
  32. # define yyWrite(s) (void) fputs (s, yyf)
  33. # define yyWriteNl (void) fputc ('\n', yyf)
  34.  
  35. # line 26 "TempScalars.puma"
  36.  
  37. # include "Idents.h"
  38. # include "StringMe.h"
  39.  
  40. # include "protocol.h"
  41.  
  42. # include "Transfor.h"  /* AppendDECLS, CombineACF */
  43. # include "Types.h"      /* ArrayCompType */
  44.  
  45. static tTree new_decls;          /* global used for new declarations */
  46. static tTree new_stmts;          /* global used when creating the local */
  47.  
  48.  
  49.  
  50. static FILE * yyf = stdout;
  51.  
  52. static void yyAbort
  53. # ifdef __cplusplus
  54.  (char * yyFunction)
  55. # else
  56.  (yyFunction) char * yyFunction;
  57. # endif
  58. {
  59.  (void) fprintf (stderr, "Error: module TempScalars, routine %s failed\n", yyFunction);
  60.  exit (1);
  61. }
  62.  
  63. void TempScalarsInitBody ARGS((tTree t));
  64. void TempScalarsDoneBody ARGS((tTree t));
  65. tTree ExtractScalarMovements ARGS((tTree exp, tTree * new_assigns));
  66. static tTree DoIt ARGS((tTree exp));
  67. static tTree MakeScalarTemporary ARGS((tTree var));
  68. static tTree NewTempScalarVar ARGS((tDefinitions Obj, int no));
  69. static tDefinitions MakeNewScalarObject ARGS((tDefinitions Obj, tIdent new_name));
  70. static int NextNumber ARGS((tIdent name, tTree assignments));
  71. static bool IsUsed ARGS((tIdent name, tTree assignment));
  72. tTree MakeNewLoopVar ARGS((int n));
  73. static tDefinitions MakeNewLoopVarObj ARGS((tIdent id));
  74.  
  75. void TempScalarsInitBody
  76. # if defined __STDC__ | defined __cplusplus
  77. (register tTree t)
  78. # else
  79. (t)
  80.  register tTree t;
  81. # endif
  82. {
  83.   if (t == NoTree) return;
  84.   if (t->Kind == kBODY_NODE) {
  85. # line 48 "TempScalars.puma"
  86.   {
  87. # line 49 "TempScalars.puma"
  88.    new_decls = mDECL_EMPTY ();
  89.   }
  90.    return;
  91.  
  92.   }
  93. # line 52 "TempScalars.puma"
  94.   {
  95. # line 53 "TempScalars.puma"
  96.    printf ("Illegal Call of TempScalarsInitBody");
  97. # line 54 "TempScalars.puma"
  98.    kill_in_protocol ();
  99.   }
  100.    return;
  101.  
  102. ;
  103. }
  104.  
  105. void TempScalarsDoneBody
  106. # if defined __STDC__ | defined __cplusplus
  107. (register tTree t)
  108. # else
  109. (t)
  110.  register tTree t;
  111. # endif
  112. {
  113.   if (t == NoTree) return;
  114.   if (t->Kind == kBODY_NODE) {
  115. # line 65 "TempScalars.puma"
  116.   {
  117. # line 67 "TempScalars.puma"
  118.    tree_protocol ("This are new created scalar temporaries : \n", new_decls);
  119. # line 68 "TempScalars.puma"
  120.  t->BODY_NODE.DECLS = AppendDECLS (t->BODY_NODE.DECLS, new_decls);
  121.   }
  122.    return;
  123.  
  124.   }
  125. # line 71 "TempScalars.puma"
  126.   {
  127. # line 72 "TempScalars.puma"
  128.    printf ("Illegal Call of TempScalarsDoneBody");
  129. # line 73 "TempScalars.puma"
  130.    kill_in_protocol ();
  131.   }
  132.    return;
  133.  
  134. ;
  135. }
  136.  
  137. tTree ExtractScalarMovements
  138. # if defined __STDC__ | defined __cplusplus
  139. (register tTree exp, register tTree * new_assigns)
  140. # else
  141. (exp, new_assigns)
  142.  register tTree exp;
  143.  register tTree * new_assigns;
  144. # endif
  145. {
  146. # line 96 "TempScalars.puma"
  147.  {
  148.   tTree result;
  149.   tTree e;
  150.   {
  151. # line 98 "TempScalars.puma"
  152.  
  153. # line 99 "TempScalars.puma"
  154.  
  155. # line 101 "TempScalars.puma"
  156.  new_stmts = NoTree;
  157.    e = DoIt (exp);
  158.    result = new_stmts;
  159.  
  160.   }
  161.    * new_assigns = result;
  162.   {
  163.    return e;
  164.   }
  165.  }
  166.  
  167. }
  168.  
  169. static tTree DoIt
  170. # if defined __STDC__ | defined __cplusplus
  171. (register tTree exp)
  172. # else
  173. (exp)
  174.  register tTree exp;
  175. # endif
  176. {
  177.  
  178.   switch (exp->Kind) {
  179.   case kBTE_LIST:
  180. # line 119 "TempScalars.puma"
  181.   {
  182. # line 120 "TempScalars.puma"
  183.  exp->BTE_LIST.Elem = DoIt (exp->BTE_LIST.Elem);
  184.      exp->BTE_LIST.Next = DoIt (exp->BTE_LIST.Next);
  185.  
  186.   }
  187.    return exp;
  188.  
  189.   case kBTE_EMPTY:
  190. # line 126 "TempScalars.puma"
  191.    return exp;
  192.  
  193.   case kBTV_LIST:
  194. # line 130 "TempScalars.puma"
  195.   {
  196. # line 131 "TempScalars.puma"
  197.  exp->BTV_LIST.Elem = DoIt (exp->BTV_LIST.Elem);
  198.      exp->BTV_LIST.Next = DoIt (exp->BTV_LIST.Next);
  199.  
  200.   }
  201.    return exp;
  202.  
  203.   case kBTV_EMPTY:
  204. # line 137 "TempScalars.puma"
  205.    return exp;
  206.  
  207.   case kBTP_LIST:
  208. # line 141 "TempScalars.puma"
  209.   {
  210. # line 142 "TempScalars.puma"
  211.  exp->BTP_LIST.Elem = DoIt (exp->BTP_LIST.Elem);
  212.      exp->BTP_LIST.Next = DoIt (exp->BTP_LIST.Next);
  213.  
  214.   }
  215.    return exp;
  216.  
  217.   case kBTP_EMPTY:
  218. # line 148 "TempScalars.puma"
  219.    return exp;
  220.  
  221.   case kVAR_PARAM:
  222. # line 152 "TempScalars.puma"
  223.   {
  224. # line 153 "TempScalars.puma"
  225.  exp->VAR_PARAM.V = DoIt (exp->VAR_PARAM.V);
  226.  
  227.   }
  228.    return exp;
  229.  
  230.   case kADDR:
  231. # line 158 "TempScalars.puma"
  232.   {
  233. # line 159 "TempScalars.puma"
  234.  exp->ADDR.E = DoIt (exp->ADDR.E);
  235.  
  236.   }
  237.    return exp;
  238.  
  239.   case kDUMMY_EXP:
  240. # line 164 "TempScalars.puma"
  241.    return exp;
  242.  
  243.   case kSLICE_EXP:
  244. # line 168 "TempScalars.puma"
  245.   {
  246. # line 169 "TempScalars.puma"
  247.  exp->SLICE_EXP.START = DoIt (exp->SLICE_EXP.START);
  248.      exp->SLICE_EXP.STOP  = DoIt (exp->SLICE_EXP.STOP);
  249.      exp->SLICE_EXP.INC   = DoIt (exp->SLICE_EXP.INC);
  250.  
  251.   }
  252.    return exp;
  253.  
  254.   case kOP_EXP:
  255. # line 176 "TempScalars.puma"
  256.   {
  257. # line 178 "TempScalars.puma"
  258.  exp->OP_EXP.OPND1 = DoIt (exp->OP_EXP.OPND1);
  259.      exp->OP_EXP.OPND2 = DoIt (exp->OP_EXP.OPND2);
  260.  
  261.   }
  262.    return exp;
  263.  
  264.   case kOP1_EXP:
  265. # line 184 "TempScalars.puma"
  266.   {
  267. # line 185 "TempScalars.puma"
  268.  exp->OP1_EXP.OPND = DoIt (exp->OP1_EXP.OPND);
  269.   }
  270.    return exp;
  271.  
  272.   case kFUNC_CALL_EXP:
  273.   if (Definitions_IsType (exp->FUNC_CALL_EXP.FUNC_ID->PROC_OBJ.Object, kObject)) {
  274. # line 189 "TempScalars.puma"
  275.   {
  276. # line 190 "TempScalars.puma"
  277.  exp->FUNC_CALL_EXP.FUNC_PARAMS = DoIt (exp->FUNC_CALL_EXP.FUNC_PARAMS);
  278.   }
  279.    return exp;
  280.  
  281.   }
  282.   break;
  283.   case kVAR_EXP:
  284. # line 194 "TempScalars.puma"
  285.   {
  286. # line 195 "TempScalars.puma"
  287.  exp->VAR_EXP.V = DoIt (exp->VAR_EXP.V);
  288.   }
  289.    return exp;
  290.  
  291.   case kCONST_EXP:
  292. # line 199 "TempScalars.puma"
  293.    return exp;
  294.  
  295.   case kARRAY_EXP:
  296. # line 203 "TempScalars.puma"
  297.   {
  298. # line 204 "TempScalars.puma"
  299.  exp->ARRAY_EXP.ELEMENTS = DoIt (exp->ARRAY_EXP.ELEMENTS);
  300.   }
  301.    return exp;
  302.  
  303.   case kUSED_VAR:
  304. # line 208 "TempScalars.puma"
  305.    return exp;
  306.  
  307.   case kLOOP_VAR:
  308. # line 212 "TempScalars.puma"
  309.    return exp;
  310.  
  311.   case kINDEXED_VAR:
  312.   if (exp->INDEXED_VAR.IND_VAR->Kind == kUSED_VAR) {
  313. # line 216 "TempScalars.puma"
  314.   {
  315. # line 218 "TempScalars.puma"
  316.    if (! (TreeRank (exp) == 0)) goto yyL19;
  317.   {
  318. # line 219 "TempScalars.puma"
  319.    if (! (TreeDistribution (exp->INDEXED_VAR.IND_VAR) != 0)) goto yyL19;
  320.   {
  321. # line 223 "TempScalars.puma"
  322.  exp->INDEXED_VAR.IND_EXPS = DoIt (exp->INDEXED_VAR.IND_EXPS);
  323.   }
  324.   }
  325.   }
  326.    return MakeScalarTemporary (exp);
  327. yyL19:;
  328.  
  329. # line 228 "TempScalars.puma"
  330.   {
  331. # line 229 "TempScalars.puma"
  332.  exp->INDEXED_VAR.IND_EXPS = DoIt (exp->INDEXED_VAR.IND_EXPS);
  333.   }
  334.    return exp;
  335.  
  336.   }
  337.   break;
  338.   case kSUBSTRING_VAR:
  339. # line 233 "TempScalars.puma"
  340.   {
  341. # line 234 "TempScalars.puma"
  342.  exp->SUBSTRING_VAR.IND_EXP = DoIt (exp->SUBSTRING_VAR.IND_EXP);
  343.   }
  344.    return exp;
  345.  
  346.   case kDO_EXP:
  347. # line 238 "TempScalars.puma"
  348.   {
  349. # line 239 "TempScalars.puma"
  350.  exp->DO_EXP.RANGE = DoIt (exp->DO_EXP.RANGE);
  351.      exp->DO_EXP.BODY  = DoIt (exp->DO_EXP.BODY);
  352.  
  353.   }
  354.    return exp;
  355.  
  356.   case kDO_VAR:
  357. # line 245 "TempScalars.puma"
  358.   {
  359. # line 246 "TempScalars.puma"
  360.  exp->DO_VAR.RANGE = DoIt (exp->DO_VAR.RANGE);
  361.      exp->DO_VAR.BODY  = DoIt (exp->DO_VAR.BODY);
  362.  
  363.   }
  364.    return exp;
  365.  
  366.   }
  367.  
  368. # line 252 "TempScalars.puma"
  369.   {
  370. # line 253 "TempScalars.puma"
  371.    failure_protocol ("TempScalars", "DoIt", exp);
  372.   }
  373.    return exp;
  374.  
  375. }
  376.  
  377. static tTree MakeScalarTemporary
  378. # if defined __STDC__ | defined __cplusplus
  379. (register tTree var)
  380. # else
  381. (var)
  382.  register tTree var;
  383. # endif
  384. {
  385.   if (var->Kind == kINDEXED_VAR) {
  386.   if (var->INDEXED_VAR.IND_VAR->Kind == kUSED_VAR) {
  387. # line 270 "TempScalars.puma"
  388.  {
  389.   int number;
  390.   tTree scvar;
  391.   tTree stmt;
  392.   {
  393. # line 272 "TempScalars.puma"
  394.  
  395. # line 274 "TempScalars.puma"
  396.  
  397. # line 275 "TempScalars.puma"
  398.  
  399. # line 277 "TempScalars.puma"
  400.  number = NextNumber (var->INDEXED_VAR.IND_VAR->USED_VAR.VARNAME->VAR_OBJ.Ident, new_stmts);
  401.  
  402.      scvar = NewTempScalarVar (var->INDEXED_VAR.IND_VAR->USED_VAR.VARNAME->VAR_OBJ.Object, number);
  403.      scvar = mUSED_VAR (scvar);
  404.  
  405.      stmt = mASSIGN_STMT (scvar, mVAR_EXP (var));
  406.      stmt = mACF_BASIC (stmt);
  407.      new_stmts = CombineACF (new_stmts, mACF_LIST (stmt, NoTree));
  408.  
  409.  
  410.   }
  411.   {
  412.    return CopyTree (scvar);
  413.   }
  414.  }
  415.  
  416.   }
  417.   }
  418.  yyAbort ("MakeScalarTemporary");
  419. }
  420.  
  421. static tTree NewTempScalarVar
  422. # if defined __STDC__ | defined __cplusplus
  423. (register tDefinitions Obj, register int no)
  424. # else
  425. (Obj, no)
  426.  register tDefinitions Obj;
  427.  register int no;
  428. # endif
  429. {
  430. # line 304 "TempScalars.puma"
  431.  
  432. char string1[MAXID_LENGTH], string2[MAXID_LENGTH];
  433. tIdent newname;
  434. tObject scalar_obj;
  435. tTree t;
  436.  
  437.   if (Obj->Kind == kVarObject) {
  438. # line 311 "TempScalars.puma"
  439.   {
  440. # line 313 "TempScalars.puma"
  441.  GetString (Obj->VarObject.ident, string1);
  442.      sprintf (string2, "%s_SC%d", string1, no);
  443.      newname = MakeIdent (string2, strlen (string2));
  444.  
  445.      scalar_obj = GetLocalDecl (newname);
  446.      if (scalar_obj == NoObject)
  447.        scalar_obj = MakeNewScalarObject (Obj, newname);
  448.  
  449.      t = mVAR_OBJ (0, newname);
  450.      t->VAR_OBJ.Object = scalar_obj;
  451.  
  452.   }
  453.    return t;
  454.  
  455.   }
  456.  yyAbort ("NewTempScalarVar");
  457. }
  458.  
  459. static tDefinitions MakeNewScalarObject
  460. # if defined __STDC__ | defined __cplusplus
  461. (register tDefinitions Obj, register tIdent new_name)
  462. # else
  463. (Obj, new_name)
  464.  register tDefinitions Obj;
  465.  register tIdent new_name;
  466. # endif
  467. {
  468. # line 337 "TempScalars.puma"
  469.  {
  470.   tTree new_decl;
  471.   tDefinitions new_obj;
  472.   {
  473. # line 339 "TempScalars.puma"
  474.  
  475. # line 340 "TempScalars.puma"
  476.  
  477. # line 342 "TempScalars.puma"
  478.  new_decl  = mVAR_DECL (new_name, 0, CopyTree (ArrayCompType (Obj)));
  479.  
  480.     new_decls = mDECL_LIST (new_decl, new_decls);
  481.  
  482.     new_obj = mVarObject (new_name, new_decl,
  483.                mVarLocal (0, 0), 0, mSerialDistribution (0, 0));
  484.  
  485.     InsertEntry (new_obj);
  486.  
  487.   }
  488.   {
  489.    return new_obj;
  490.   }
  491.  }
  492.  
  493. }
  494.  
  495. static int NextNumber
  496. # if defined __STDC__ | defined __cplusplus
  497. (register tIdent name, register tTree assignments)
  498. # else
  499. (name, assignments)
  500.  register tIdent name;
  501.  register tTree assignments;
  502. # endif
  503. {
  504. # line 369 "TempScalars.puma"
  505.   {
  506. # line 370 "TempScalars.puma"
  507.    if (! (assignments == NoTree)) goto yyL1;
  508.   }
  509.    return 1;
  510. yyL1:;
  511.  
  512.   if (assignments->Kind == kACF_LIST) {
  513.   if (assignments->ACF_LIST.Elem->Kind == kACF_BASIC) {
  514.   if (assignments->ACF_LIST.Elem->ACF_BASIC.BASIC_STMT->Kind == kASSIGN_STMT) {
  515. # line 374 "TempScalars.puma"
  516.   {
  517. # line 375 "TempScalars.puma"
  518.    if (! (IsUsed (name, assignments->ACF_LIST.Elem->ACF_BASIC.BASIC_STMT->ASSIGN_STMT.ASSIGN_EXP))) goto yyL2;
  519.   }
  520.    return NextNumber (name, assignments->ACF_LIST.Next) + 1;
  521. yyL2:;
  522.  
  523.   }
  524.   }
  525. # line 379 "TempScalars.puma"
  526.    return NextNumber (name, assignments->ACF_LIST.Next);
  527.  
  528.   }
  529.  yyAbort ("NextNumber");
  530. }
  531.  
  532. static bool IsUsed
  533. # if defined __STDC__ | defined __cplusplus
  534. (register tIdent name, register tTree assignment)
  535. # else
  536. (name, assignment)
  537.  register tIdent name;
  538.  register tTree assignment;
  539. # endif
  540. {
  541.   if (assignment == NoTree) return false;
  542.   if (assignment->Kind == kVAR_EXP) {
  543.   if (assignment->VAR_EXP.V->Kind == kINDEXED_VAR) {
  544.   if (assignment->VAR_EXP.V->INDEXED_VAR.IND_VAR->Kind == kUSED_VAR) {
  545. # line 385 "TempScalars.puma"
  546.   {
  547. # line 386 "TempScalars.puma"
  548.    if (! (assignment->VAR_EXP.V->INDEXED_VAR.IND_VAR->USED_VAR.VARNAME->VAR_OBJ.Ident == name)) goto yyL1;
  549.   }
  550.    return true;
  551. yyL1:;
  552.  
  553.   }
  554.   }
  555.   }
  556.   return false;
  557. }
  558.  
  559. tTree MakeNewLoopVar
  560. # if defined __STDC__ | defined __cplusplus
  561. (register int n)
  562. # else
  563. (n)
  564.  register int n;
  565. # endif
  566. {
  567. # line 398 "TempScalars.puma"
  568.  
  569. char loop_name[10];
  570. tIdent loop_id;
  571. tObject obj;
  572. tTree var;
  573.  
  574. # line 405 "TempScalars.puma"
  575.   {
  576. # line 406 "TempScalars.puma"
  577.   sprintf (loop_name, "I_%d", n);
  578.       loop_id = MakeIdent (loop_name, strlen (loop_name));
  579.  
  580.       obj = GetLocalDecl (loop_id);
  581.  
  582.       if (obj == NoObject)
  583.          {
  584.            obj = MakeNewLoopVarObj (loop_id);
  585.          }
  586.  
  587.       var = mVAR_OBJ (0, loop_id);
  588.       var->VAR_OBJ.Object = obj;
  589.  
  590.       var = mLOOP_VAR (var);
  591.  
  592.   }
  593.    return var;
  594.  
  595. }
  596.  
  597. static tDefinitions MakeNewLoopVarObj
  598. # if defined __STDC__ | defined __cplusplus
  599. (register tIdent id)
  600. # else
  601. (id)
  602.  register tIdent id;
  603. # endif
  604. {
  605. # line 426 "TempScalars.puma"
  606.  
  607. tTree new_decl;
  608. tObject obj;
  609. tIdent name;
  610. char s[10];
  611.  
  612. # line 433 "TempScalars.puma"
  613.   {
  614. # line 434 "TempScalars.puma"
  615.  new_decl = mVAR_DECL (id, 0, mINTEGER_TYPE(4));
  616.  
  617.      new_decls = mDECL_LIST (new_decl, new_decls);
  618.  
  619.      obj  = mVarObject (
  620.                  id, new_decl, mVarLocal (0, 0),
  621.                  0,
  622.                  mSerialDistribution (0, 0) );
  623.  
  624.      InsertEntry (obj);
  625.  
  626.   }
  627.    return obj;
  628.  
  629. }
  630.  
  631. void BeginTempScalars ()
  632. {
  633. }
  634.  
  635. void CloseTempScalars ()
  636. {
  637. }
  638.